<template>
    <div id="dr4">
        <Breadcrumb style="margin-bottom: 10px">
            <BreadcrumbItem to="/superAdmin">首页</BreadcrumbItem>
            <BreadcrumbItem>运营分析平台</BreadcrumbItem>
            <BreadcrumbItem>每日点击量统计分析</BreadcrumbItem>
        </Breadcrumb>
        <DatePicker v-model="startYearMonthDay" type="month" placeholder="选择年月" style="width: 150px"></DatePicker>
        &nbsp;
        <Button type="info" @click="getData()">查询</Button>
        <Table style="margin-top: 10px" :maxWidth="1000" :minWidth="10" stripe :columns="columns" :data="data"
               v-if="data&&data.length>0"></Table>
        <div id="loading" v-if="loading">
            <div class="spinner">
                <div class="double-bounce1"></div>
                <div class="double-bounce2"></div>
            </div>
        </div>

    </div>
</template>
<script type="text/ecmascript-6">
    import sessionUtils from '../../model/sessionUtils';
    import ipServer from '../../model/ip';
    import Axios from 'axios';
    export default{
        data(){
            return {
                loading: false,
                startYearMonthDay: "",
                columns: [],
                data: []
            }
        },
        mounted(){
            this.getData();
        },
        methods: {
            getData(){
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                if (this.startYearMonthDay) {
                    param.append('startYearMonth', sessionUtils.DateToMonth(this.startYearMonthDay) + "");
                }
                this.loading = true;
                Axios.post(ipServer + "pageHome/selectEveryDayAdsvertHitStatistical", param)
                        .then(res => {
                            if (res.data.code == 0) {
                                sessionUtils.setSession("token", res.data.token);
                                console.log(JSON.stringify(res.data.data));
                                this.columns = [{
                                    title: '日期',
                                    key: 'createTimeStr'
                                }];

                                if (res.data.data && res.data.data.length > 0) {
                                    if (res.data.data[0].homePageAdvertList && res.data.data[0].homePageAdvertList.length > 0) {
                                        for (var i = 0; i < res.data.data[0].homePageAdvertList.length; i++) {
                                            var column = {title: "", key: ""};
                                            column.title = res.data.data[0].homePageAdvertList[i].advertName;
                                            column.key = "a" + i;
                                            this.columns.push(column);
                                        }
                                    }
                                }


                                if (res.data.data && res.data.data.length > 0) {
                                    for (var i = 0; i < res.data.data.length; i++) {
                                        for(var j = 0; j < res.data.data[i].homePageAdvertList.length; j++){
                                            res.data.data[i]["a"+j]=res.data.data[i].homePageAdvertList[j].sum;
                                        }
                                    }
                                }





                                this.data = res.data.data;
                            } else if (res.data.code == 3) {
                                sessionUtils.clear();
                                this.$router.push("/login");
                                this.$Message.info(res.data.msg);
                            } else {
                                this.$Message.info(res.data.msg);
                            }
                            this.loading = false;
                        })
                        .catch(err=> {
                            this.loading = false;
                            this.$Message.info(err);
                            console.log("错误" + err.toString());
                        });
            }
        }
    }
</script>


<style scoped>
    @import "../../assets/css/loading.css";

</style>